HTMLElement.prototype.index = function () {
    return index(this, 0);
    function index(e, i) {
        if (e.previousElementSibling === null) {
            return i;
        } else {
            return index(e.previousElementSibling, i + 1);
        }
    }
}
